package array;

public class maxArray {
    public int maxSubArray(int[] nums){
        if (nums.length<=1){
            System.out.println(nums[0]);
        }
        int[]dp=new int[nums.length];
        dp[0]=nums[0];
        for (int i=1;i<nums.length;i++){
            dp[i]=maxNum(dp[i-1]+nums[i],nums[i]);
        }
        int temp=dp[0];
        for (int j=1;j<dp.length;j++){
            if (dp[j]>temp){
                temp=dp[j];
            }
        }
        return temp;
    }
    public static int maxNum(int a,int b){
        if (a<b){
            return b;
        }
        else{
            return a;
        }
    }

    public static void main(String[] args) {
        int[]nums={9,-1,6,8,2,7,4,3,0,-6,9};
        maxArray maxArray=new maxArray();
        maxArray.maxSubArray(nums);
    }

}
